package com.itheima.springboot_06_demo.controller;

import com.itheima.springboot_06_demo.pojo.Member;
import com.itheima.springboot_06_demo.pojo.Result;
import com.itheima.springboot_06_demo.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class MemberController {

    @Autowired
    private MemberService memberService;

    // 查询所有成员信息
    @GetMapping("/members")
    public Result memberList(){
        log.info("查询所有成员信息. . .");
        List<Member> memberList = memberService.list();
        return Result.success(memberList);
    }

    // 添加成员信息
    @PostMapping("/members")
    public Result addMember(@RequestBody Member member){
        log.info("添加成员. . .");
        memberService.add(member);
        return Result.success();
    }

}
